package jintian作业;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

class Book1{
    private int bid;
    private String name;
    private float price;

    public Book1(int bid, String name, float price) {
        this.bid = bid;
        this.name = name;
        this.price = price;
    }

    public int getBid() {
        return bid;
    }

    public void setBid(int bid) {
        this.bid = bid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return "Book1{" +
                "bid=" + bid +
                ", name='" + name + '\'' +
                ", price=" + price +
                '}';
    }
    public void sell(){
        System.out.println(this.name+"书本被卖完了");
    }
    private void sell(float price,String person){
        String str =this.name;
        String str1 =Float.toString(price);

        System.out.println(this.name+str.concat("卖给了")+person+person.concat(",卖了")+this.price+str1.concat("元"));
    }

}
public class Kill {
    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException {
        Class c =Book1.class;
        Constructor con = c.getDeclaredConstructor(int.class,String.class,float.class);
        Book1 b1 =(Book1) con.newInstance(12,"水浒传",123.6f);
        Method m1 = c.getDeclaredMethod("sell");
        m1.invoke(b1);
        Method m2 =c.getDeclaredMethod("sell", float.class, String.class);
        m2.setAccessible(true);
        m2.invoke(b1,123.6f,"小辉");
    }
}
